package com.cnsuning.jobtool.jobtools.rdrscheck;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CheckTest {
    @Test
    public void test() throws IOException {
        File midFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrscheck\\中间库.txt");
        File tarFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrscheck\\目标库.txt");
        List<String> midFileList = FileUtils.readLines(midFile);
        List<String> tarFileList = FileUtils.readLines(tarFile);
        Map<String,Integer> tarMap = new HashMap<>();
        for (String orderId: tarFileList)
        {
            tarMap.put(orderId,0);
        }
        tarFileList.clear();
        tarFileList = null;
        File recordFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrscheck\\record.txt");
        if (recordFile.exists()) recordFile.delete();
        //循环中间维度
        for (String orderId:midFileList)
        {
            Integer integer = tarMap.get(orderId);
            if (integer == null)
            {
                FileUtils.writeStringToFile(recordFile,orderId+"\n",true);
            }
        }

    }

    @Test
    public void generateSql() throws IOException {


        File recordFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrscheck\\record.txt");
        File targetFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrscheck\\targetFile_omsdm_025.txt");
        String sqlTemplate = "select * from so_ord where order_id = '%s';\n";
        List<String> ordernoList = FileUtils.readLines(recordFile);
        for (int i = 0; i < ordernoList.size(); i++) {
            if (Long.parseLong(ordernoList.get(i))%8 == 0) {
                String sql = String.format(sqlTemplate, ordernoList.get(i));
                FileUtils.writeStringToFile(targetFile, sql, true);
            }
        }
    }

    @Test
    public void test2()
    {
        DecimalFormat decimalFormat = new DecimalFormat("0000");
        String format = decimalFormat.format(22);
        System.out.println(format);
    }
}
